import pytest
import requests
import json
import yaml

#json数据驱动
def data_json():
    with open("data.json","r",encoding="utf8")as f:
        return json.load(f)
#yaml数据驱动
def data_yaml():
    with open("data.yaml","r",encoding="utf8")as f:
        return yaml.safe_load(f)

class TestCase1():
    token =None
    spid = None
    def setup_method(self):
        print("开始测试前")
    def teardown_method(self):
        print("结束后")


    @pytest.mark.parametrize("d",data_yaml())
    #登录接口
    def test_login(self,d):
        url = "http://10.59.9.12:7001/api/public/login"
        head = {"Content-Type": "application/json"}
        data = {"username": d.get("username"), "password": d.get("password")}
        res = requests.post(url=url, headers=head, json=data)
        print(res.json())
        # TestCase1.token = "Bearer "+res.json()["data"]["token"]
    #查看商品详情
    # def test_cksp(self):
    #     url = "http://10.59.9.12:7001/api/goods/view?id=69"
    #     head = {"Content-Type": "application/json"}
    #     res = requests.get(url=url, headers=head)
    #     print(res.json())
    # #加入购物车接口
    # def test_Add(self):
    #     url = "http://10.59.9.12:7001/api/cart/add"
    #     head = {"Content-Type": "application/json","Auth-Token":TestCase1.token}
    #     data = {"id":69,"sku_id":"","num":1}
    #     res = requests.post(url=url, headers=head, json=data)
    #     print(res.json())
    #
    #
    # #查看购物车列表
    # def test_chakanGWC(self):
    #     url = "http://10.59.9.12:7001/api/cart?page=1"
    #     head = {"Content-Type": "application/json", "Auth-Token": TestCase1.token}
    #     res = requests.get(url=url, headers=head)
    #     print(res.json())
    #     #查看购物车列表里提取商品ID变量，让“确认订单”和“支付”使用
    #     TestCase1.spid = res.json()["data"]["list"][0]["id"]
    # #确定订单接口
    # def test_qrdd(self):
    #     url = f"http://10.59.9.12:7001/api/order/confirm?id={TestCase1.spid}&type=cart&shipping_type=1"
    #     head = {"Content-Type": "application/json","Auth-Token":TestCase1.token}
    #     res = requests.get(url=url, headers=head)
    #     print(res.json())
    # # #提交订单接口
    # def test_tjdd(self):
    #     url ="http://10.59.9.12:7001/api/order/create"
    #     head={"Content-Type": "application/json","Auth-Token":TestCase1.token}
    #     data={"id":TestCase1.spid,"type":"cart","address_id":801,"store_id":1,"shipping_type":1,"bonus_id":"0","payment":"balance","remarks":"","source":1,"url":"http://10.59.9.12:7001/wap/pages/cart/confirm?id=3452&type=cart"}
    #     res = requests.post(url=url,headers=head,json=data)
    #     print(res.json())